package com.seecode;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.seecode.Utils.Utils;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class FunListActivity extends AppCompatActivity {
    private ListView listView1;
    private List<String> dataList = new ArrayList<>();
    private ArrayAdapter<String> adapter;
    private TextView    title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fun_list);

        title =(TextView)findViewById(R.id.title);
        listView1 =(ListView) findViewById(R.id.list1);
        adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,dataList);
        dataInit();
        listView1.setAdapter(adapter);
        adapter.notifyDataSetChanged();

        listView1.setOnItemClickListener(new AdapterView.OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                String funName = dataList.get(position);
                //Utils.loadUrl(className);
                //Toast.makeText(HistoryActivity.this,className,Toast.LENGTH_SHORT).show();
                Logs.i("you touch"+funName);
                Utils.readFun(funName);


                finish();

            }
        });

    }


    public void dataInit(){

        Intent intent = getIntent();
        String[] listName = intent.getStringArrayExtra("funlist");
        int  blocks  = intent.getIntExtra("blocks",0);
        int currentBLock  = intent.getIntExtra("currentBlock",0);
        int n = listName.length;
        for(int i=0; i < n ;i++){

            dataList.add(listName[i]);
        }

        String strtitile ="函数列表("+n+")"+"blocks:"+blocks+" cur:"+currentBLock;
        title.setText(strtitile);



    }
}
